package com.chaoyi.controller;


import com.chaoyi.enums.ResultStatus;
import com.chaoyi.exception.ParameterException;
import com.chaoyi.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;


/**
 * 错误处理器
 *
 * @author xuanqicheng
 */
@ControllerAdvice
public class ControllerExceptionHandler {

    /**
     * Expception 处理
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    public ResultVo handlerParameterException(Exception ex){

        ResultVo resultVo = new ResultVo(ResultStatus.INNER_ERROR.getCode(),ResultStatus.INNER_ERROR.getMessage(),
                new HashMap<>(0));

        return resultVo;
    }

    @ExceptionHandler(ParameterException.class)
    @ResponseBody
    public ResultVo handlerParameterException(ParameterException ex){

        ResultVo resultVo = new ResultVo(ex.getCode(),ex.getMessage(),new HashMap<>(0));

        return resultVo;
    }



}
